/**
 * Created by shizi on 2018/12/27.
 */

// 加载React
import React from 'react'
// 加载Component
import { Component, PureComponent } from 'react'
//全局配置
import Config from '../../config/config'
// import styles from './FlagStyle.less'
// 选项卡、表格、弹出确认框
import { Row, } from 'antd'
// 导出组件

let isFlagBtn = Config.isFlagBtn

export default class FlagBtn extends Component {
  constructor (props, context) {
    super(props, context)
    this.state = {
      subElements:[]
    }
  }
  
  componentDidMount () {
    // console.log(this.props)
    let subElements = JSON.parse(localStorage.getItem('navBar')).subElements 
    // console.log('subElements',JSON.parse(localStorage.getItem('navBar')).subElements)
    this.setState({
      node: this.props.node,
      btnId: this.props.btnId,
      actionType: this.props.actionType || null,
      subElements
    })
  }
  
  componentWillReceiveProps (nextprops) {
    if (nextprops.node != this.state.node || nextprops.btnId!=this.state.btnId) {
      this.setState({
        node: nextprops.node,
        btnId: nextprops.btnId
      })
    }
    
  }
  
  isRenderBtn () {
    let {node, btnId,subElements} = this.state
    // console.log(btnId)
    if (isFlagBtn) {
      return node
    } else {
      return node
      // if (subElements.indexOf(Number(btnId)) > -1 || !btnId) {
      //   return node
      // } else {
      //   console.log('btn is null')
      //   return null
      // }
    }
    
  }
  
  render () {
    let {actionType} = this.state
    return (
      <span style={actionType ? {marginRight: '20px'} : null}>
                {this.isRenderBtn()}
            </span>
    )
  }
}
